package com.hex.liyue.giftmodule.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hex.liyue.LiYueApplication;
import com.hex.liyue.R;

import java.util.List;
import java.util.Map;

/**
 * Created by WJ on 2016/6/12.
 */
public class AdapterConfirmReceipt extends RecyclerView.Adapter<AdapterConfirmReceipt.MyHolder> {
    private List<Map<String, Object>> gift_list;

    public AdapterConfirmReceipt(List<Map<String, Object>> gift_list) {
        this.gift_list = gift_list;
//        jsonObject.put("gift_id", dataBean.gift_id);
//        jsonObject.put("gift_url", dataBean.gift_url);
//        jsonObject.put("gift_brand", dataBean.gift_brand);
//        jsonObject.put("gift_name", dataBean.gift_name);
//        jsonObject.put("gift_num", dataBean.current_gift_num);
//        jsonObject.put("gift_price", dataBean.price);
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_confirm_receipt, null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, int position) {
        Map<String, Object> map = gift_list.get(position);
        Glide.with(LiYueApplication.getInstance())
                .load(map.get("gift_url")).centerCrop()
                .error(R.drawable.no_icon)
                .into(holder.iv_avater);
        holder.tv_brand.setText(map.get("gift_brand")+"");
        holder.tv_name.setText(map.get("gift_name")+"");
        holder.tv_num.setText("数量：x " + map.get("gift_num"));
        holder.tv_price.setText("金额:￥" + (Integer.parseInt(map.get("gift_num").toString()) * Double.parseDouble(map.get("gift_price").toString())));
    }

    @Override
    public int getItemCount() {
        if (gift_list != null) {
            return gift_list.size();
        }
        return 0;
    }

    class MyHolder extends RecyclerView.ViewHolder {
        ImageView iv_avater;
        TextView tv_brand, tv_name, tv_num, tv_price;

        public MyHolder(View itemView) {
            super(itemView);
            iv_avater = (ImageView) itemView.findViewById(R.id.iv_avater);
            tv_brand = (TextView) itemView.findViewById(R.id.tv_brand);
            tv_name = (TextView) itemView.findViewById(R.id.tv_name);
            tv_num = (TextView) itemView.findViewById(R.id.tv_num);
            tv_price = (TextView) itemView.findViewById(R.id.tv_price);
        }
    }
}
